//Marking code
function SetAllCheckboxes(val){
  resPool = $(".panel");
  field = document.mngForm.mark;
  for (i = 0; i < field.length; i++){
    if(resPool[i].style.display != 'none'){
      field[i].checked = val;
    }
  }

}
$("#markAll").click(function(){SetAllCheckboxes(true)});
$("#UnMarkAll").click(function(){SetAllCheckboxes(false)});

//reloading menu
$(document).ready(function(){
  $(".menuLink").click(function(){
    $("#title").html($(this).attr("title"));
    $("#contenttext").load('contents/' + $(this).attr("id") + '.jsp');  
  });
});


//Searching code
/**
 * code that searches results from the html according to search word and a selection of 
 * fields to search with
 */
$("#searchBox").keyup(function SearchPool(){
  resPool = $(".panel");
  field = document.mngForm.mark;
  searchOptions = document.mngForm.srchOptions;
  for (i = 0; i < resPool.length; i++)
    {
      fields = $(".hiddenData",resPool[i]);
      for(j = 0; j < searchOptions.length + 1 ;j++){
        if (((j == 0) || (searchOptions[j-1].checked == true)) && (fields.eq(j).attr("value").indexOf($("#searchBox").attr("value")) >= 0)){
          resPool[i].style.display = 'block';
          break; //so if we found resPool[i] we show him and not search onward so it may not hide him again
        }else{
          if (j == searchOptions.length){//only if it is the last option and we haven't found we hide and uncheck
            resPool[i].style.display = 'none';
            field[i].checked = false;
          }
        }
      }
      fields="";
    }
});
